<#include "/@inc/funcMacros.ftl"> 
<#include "/@inc/copyright.txt">
<#assign className = TriaGram + "UtlLogger">
<@pp.renameOutputFile name=className+".cpp">
</@pp.renameOutputFile>
#include "${className}.h"

#include <iostream>
#include <string>
#include <sstream>
 
int		  ${className}::_nTabs =0 ;
unsigned int	${className}::_options = 0 ;
RAWStream ${className}::_streams[3] ;

${className}Init::${className}Init(RAWStream iStreams[], unsigned int iOptions)
{
  time_t rawtime;

  time ( &rawtime );
  struct tm * timeinfo = localtime( &rawtime );

  // Thu Aug 23 14:55:02 2001
 
  if( ${className}File & iOptions )
  {
	  iStreams[0].open ("Log.txt");
	  iStreams[0] << "Created : " << asctime (timeinfo) ;
  }

  if( ${className}Warn & iOptions )
	  iStreams[1].open ("Warnings.txt");

  if( ${className}Error & iOptions )
	  iStreams[2].open ("Errors.txt");

}

${className}Init::~${className}Init(void)
{
}

void ${className}::Init( unsigned int iOptions)
{
	_options = iOptions ;

	static ${className}Init logInit(_streams, iOptions) ;

}

${className}::${className}(const char * ipTag):
_pTag(ipTag)
{
	_start = clock();
	Print(_pTag, " { --> ", "") ;
	_nTabs++ ;
}

${className}::~${className}(void)
{
	_nTabs-- ;

	std::string str ;
	if(${className}Time & _options)
	{
		clock_t end = clock();

		double diff = end - _start;

		std::ostringstream ss;
		ss << diff;
		str = " " + ss.str() ;
	}

	Print(_pTag, " } <-- ", str.c_str() ) ;
}

void ${className}::PrintTabs(int iIndex)
{
	ostream & tempStream = GetStream(iIndex) ;
	tempStream << "\n" ;
	for(int i=0 ; i < _nTabs ; i++)
	{
		 tempStream << "\t" ;
	}
}

void ${className}::Print(const char * ipTag, const char * ipAppendix, const char * ipTime )
{
	if( _options & ${className}File  )
	{
		PrintTabs(0) ;
		GetStream(0) << _pTag  << ipTime << ipAppendix;
	}

	if( _options & ${className}Cout  )
	{
		PrintTabs(-1) ;
		GetStream(-1) << _pTag  << ipAppendix ;
	}
}

ostream & ${className}::GetStream(int iIndex)
{
	if(iIndex > -1 )
		return this->_streams[iIndex] ;
	else
		return cout ;
}
